<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <title>设备定检查询报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="queryInfo.factoryname+'设备定检查询报表'"></vue2-report-header>
    <div style="padding: 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'">
        <el-form-item label="定检时间:">
          <el-date-picker v-model="queryInfo.selectdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="设备编码:">
          <el-input v-model.trim="queryInfo.equnr" placeholder="请输入" clearable></el-input>
        </el-form-item>

        <el-form-item label="设备名称:">
          <el-input v-model.trim="queryInfo.eqktx" placeholder="请输入" clearable></el-input>
        </el-form-item>

        <el-form-item label="型号:">
          <el-input v-model.trim="queryInfo.typbz" placeholder="请输入" clearable></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column label="设备编码" prop="equnr" width="160" show-overflow-tooltip></el-table-column>
        <el-table-column label="设备名称" prop="eqktx" show-overflow-tooltip></el-table-column>
        <el-table-column label="资产管理部门" prop="begru" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="设备种类" prop="eqtyp" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="设备分类" prop="eqart" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="规格" prop="groes" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="出厂日期" prop="ansdt" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="型号" prop="typbz" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="启用日期" prop="indbt" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="有效期" prop="zyxq" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="定检部门" prop="zjdbm" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="定检日期" prop="zjdrq" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="定检周期" prop="zjdzq" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="定检周期单位" prop="zzqdw" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="检定员" prop="zckusr" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="精度等级" prop="zzqdj" width="100" show-overflow-tooltip></el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[12,50,100]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>
  <script type="module">
    import { fetchSuggestion, exportExcelData, getParams } from '../Scripts/hooks/useCommonMethod.js'
    import { getFactoryInfo } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        splitDate,
        queryInfo: {
          factoryname: '',
          selectdate: '',//定检时间
          equnr: '',//设备编码
          eqktx: '',//设备名称
          typbz: '',//型号
          currentPage: 1,//当前页
          pageSize: 12//每页显示条数
        },
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        dataList: [],
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        //查询数据
        async getData(currentpage) {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/report/ZSRegularCheckinfoReport.ashx?action=getData', {
            type: 'getData',
            ...this.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.dataList = data;
          this.total = total;
        },
        // 导出excel
        async getExportExcel() {
          const config = {
            url: '../handler/report/ZSRegularCheckinfoReport.ashx?action=exportExcel',
            data: { type: 'exportExcel', ...this.queryInfo }
          }
          exportExcelData(config, this);
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        }
      },
      async mounted() {
        const factoryid = Decrypt(getParams('factoryid'));
        const factoryInfo = await getFactoryInfo({ factoryid, isMapping: '是' });
        const { factoryname } = factoryInfo[0];
        this.queryInfo.factoryname = factoryname;
        document.title = factoryname + '设备定检查询报表';
      },
      watch: {
        queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true }
      }
    })
  </script>
</body>

</html>